package com.sesample.seandroidsample;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.facebook.AppEventsConstants;
import com.facebook.AppEventsLogger;

public class MainFragment extends Fragment {

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    Button button = (Button)rootView.findViewById(R.id.button_view_products);
    button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        // Go to the product list activity
        Intent i = new Intent(getActivity(), ProductListActivity.class);
        startActivity(i);
      }
    });

    Button cartButton = (Button)rootView.findViewById(R.id.button_view_cart);
    cartButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        // Go to the product list activity
        Intent i = new Intent(getActivity(), CartActivity.class);
        startActivity(i);
      }
    });
    return rootView;
  }

  @Override
  public void onResume() {
    super.onResume();

    // Log the activated app event
    AppEventsLogger logger = AppEventsLogger.newLogger(getActivity());
    logger.logEvent(AppEventsConstants.EVENT_NAME_ACTIVATED_APP);
  }
}
